﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.Common.ValueObject;

namespace ERP_RORZE_TOOL.DBAccess
{
	class ProcessStatusDAO :BaseDAO
	{
		#region Basic Method

		public static DataTable GetAll()
		{
			return ExcuteProcedure(ToolConstants.StoreProcedure.ProcessStatus.GetAll);
		}

		public static DataTable GetOne(string processStatusId)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
						CreateParameter("@ProcessStatusID", SqlDbType.NVarChar, processStatusId)
                    };
				return ExcuteProcedure(ToolConstants.StoreProcedure.ProcessStatus.GetOne, parameters);

			}
			catch(Exception e)
			{
				throw new MyException(e);
			}

		}

		public static ProcessStatus LoadOne(string processStatusId)
		{
			ProcessStatus o = new ProcessStatus();
			DataTable dt = GetOne(processStatusId);
			if(dt.Rows.Count > 0)
			{
				o.ProcessStatusID = dt.Rows[0][ToolConstants.Entities.ProcessStatus.FieldName.ProcessStatusID].ToString();
				o.ProcessStatusJapanese = dt.Rows[0][ToolConstants.Entities.ProcessStatus.FieldName.ProcessStatusJapanese].ToString();

			}

			return o;
		}


		public static int Insert(ProcessStatus o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@ProcessStatusID", SqlDbType.NVarChar, o.ProcessStatusID),
                        CreateParameter("@ProcessStatusJapanese", SqlDbType.NVarChar, o.ProcessStatusJapanese),
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.ProcessStatus.Insert, parameters);

			}
			catch(Exception e)
			{
				throw new MyException(e);
			}

		}

		public static int Update(ProcessStatus o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@TempID", SqlDbType.NVarChar, o.TempId),
                        CreateParameter("@ProcessStatusID", SqlDbType.NVarChar, o.ProcessStatusID),
                        CreateParameter("@ProcessStatusJapanese", SqlDbType.NVarChar, o.ProcessStatusJapanese),
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.ProcessStatus.Update, parameters);
			}
			catch(Exception e)
			{
				throw new MyException(e);
			}
		}

		public static int Delete(ProcessStatus o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@ProcessStatusID", SqlDbType.NVarChar, o.ProcessStatusID)
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.ProcessStatus.Delete, parameters);
			}
			catch(Exception e)
			{
				throw new MyException(e);
			}
		}

		public static DataTable GetTemplateTable()
		{
			DataTable table = new DataTable("333_ProcessStatus");
			table.Columns.Add("ProcessStatusID");
			table.Columns.Add("ProcessStatusJapanese");

			return table;
		}

		#endregion
	}
}
